﻿Public Class masdrgkeep
    Private KEEPID = Nothing
    Private DKEEPNAME = Nothing
    Private STATUS = Nothing
    Private selectMasdrgkeep = "SELECT `keepid` as 'รหัสวิธีการเก็บรักษา', `dkeepname` as 'วิธีการเก็บรักษา', `status` as 'สถานะการเปิดใช้งาน' FROM masdrgkeep"
    'Private selectMasdrgacc = "SELECT DGTYID, DRGTYPE, convert(bit, [STATUS]) FROM MASDRGTYPE"

    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection

    Property KEEPID_ As Integer
        Get
            Return KEEPID
        End Get
        Set(value As Integer)
            KEEPID = value
        End Set
    End Property

    Property DKEEPNAME_ As String
        Get
            Return DKEEPNAME
        End Get
        Set(value As String)
            DKEEPNAME = value
        End Set
    End Property

    Property STATUS_ As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property

    Property selectMasdrgkeep_ As String
        Get
            Return selectMasdrgkeep
        End Get
        Set(value As String)

        End Set
    End Property

    Public Sub insertMasdrgkeepData()
        If TypeOf DKEEPNAME Is String Then
            If connect.GetTable("SELECT keepid FROM masdrgkeep WHERE dkeepname = '" & DKEEPNAME & "'").Rows.Count > 0 Then
                MsgBox("มีข้อมูลวิธีการเก็บยานี้อยู่ในระบบแล้ว")
            Else
                Try
                    connect = CONDB.NewConnection()
                    'connectlocal = conlocal.NewConnection()
                    'Dim dischargeID As Integer

                    connect.ExecuteNonQuery("INSERT INTO masdrgkeep (dkeepname, status) VALUES ('" & DKEEPNAME & "', '" & STATUS & "')")
                    'dischargeID = connect.ExecuteScalar("INSERT INTO masdischarge (DISCHARGE, STATUS) VALUES ('" & masdischargeDescription & "', '" & masdischargeStatus & "'); SELECT LAST_INSERT_ID();")
                    'connectlocal.ExecuteNonQuery("INSERT INTO MASDISCHARGE (DISCHGID, DISCHARGE, STATUS) VALUES ('" & dischargeID & "', '" & masdischargeDescription & "', '" & masdischargeStatus & "')")
                    MsgBox("ท่านได้ทำการเพิ่มข้อมูลวิธีการเก็บยาเรียบร้อยแล้ว")
                Catch ex As Exception
                    MsgBox(vbCrLf & ex.Message)
                End Try
                connect.Dispose()
                'connectlocal.Dispose()
            End If
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub

    Public Sub editMasdrgkeepData()
        If TypeOf DKEEPNAME Is String Then
            Try
                connect = CONDB.NewConnection()
                'connectlocal = conlocal.NewConnection()

                connect.ExecuteNonQuery("UPDATE masdrgkeep SET dkeepname = '" & DKEEPNAME & "', status = '" & STATUS & "' WHERE keepid = '" & KEEPID & "'")
                'connectlocal.ExecuteNonQuery("UPDATE MASDISCHARGE SET DISCHARGE = '" & masdischargeDescription & "', STATUS = '" & masdischargeStatus & "' WHERE DISCHGID = '" & masdischargeID & "'")
                MsgBox("ท่านได้ทำการแก้ไขข้อมูลวิธีการเก็บยาเรียบร้อยแล้ว")
            Catch ex As Exception
                MsgBox(vbCrLf & ex.Message)
            End Try
            connect.Dispose()
            'connectlocal.Dispose()
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub
End Class